package com.humngyang.com.hmy.controller;


import com.humngyang.com.hmy.entity.Userrole;
import com.humngyang.com.hmy.service.UserroleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/UserroleController")
public class UserroleController {


    @Autowired
    UserroleService userroleService;


    /**
     * Author : hmy
     *
     * @date 2020/2/24 21:05
     * describution : 添加用户和角色的信息
     **/

    @RequestMapping("/addUserRole")
    public Map<String, Object> addUserRole(@RequestBody Userrole userrole) {
        Map<String, Object> re = new HashMap<>();
        int i = userroleService.addUserRole(userrole);
        if (i > 0) {
            re.put("flag", 1);
        } else {
            re.put("flag", 0);
        }
        return re;
    }


    @RequestMapping("/getUserRoleByUserId")
    public Map<String, Object> getUserRoleByUserId(@RequestBody Userrole userrole) {
        Map<String, Object> re = new HashMap<>();
        Userrole userRoleByUserId = userroleService.getUserRoleByUserId(userrole.getUserid());
        re.put("flag", 1);
        re.put("userrole", userRoleByUserId);
        return re;
    }


}
